package jdbc1;

import java.io.IOException;
import java.sql.*;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class UpdateStudent2 {
    public static void main(String[] args) throws IOException {
        //根据学号，改姓名，和手机号
        try {
            //static{}执行了
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        Scanner sc=new Scanner(System.in);
        System.out.println("输入学号：");
        long stuno=sc.nextLong();
        sc.nextLine();
        System.out.println("请输入名字：");
        String name=sc.nextLine();
        //name=name.replace("")

        System.out.println("请输入新手机号：");
        String phone=sc.nextLine();
        String sql="update s_student set sname=?, telephone=? where stuno=?";
        System.out.println(sql);
        String url = "jdbc:mysql://localhost:3308/java83?useUnicode=true&characterEncoding=utf8&useSSL=false" +
                "&serverTimezone=Asia/Shanghai";
        try {
            Connection con = DriverManager.getConnection(url, "xukang", "Xu1234");

            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1,name);
            ps.setString(2,phone);
            ps.setLong(3,stuno);
            int line =ps.executeUpdate();
            System.out.println("改了"+line+"行");
            ps.close();
            con.close();//？
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
